const loading = {};

loading.loadingAlert = "";

loading.showLoading = function (content) {
  threads.start(function () {
    loading.loadingAlert = floaty.rawWindow(
      <frame gravity="center" id="floatyFrame" bg="#66000000">
        <vertical w="*" h="*" gravity="center">
          <progressbar w="50" h="50" />
          <text id="loadingText" gravity="center" marginTop="15"></text>
        </vertical>
      </frame>
    );
    loading.loadingAlert.setSize(-1, -1);
    // 时间悬浮窗
    if (content) {
      ui.run(function () {
        loading.loadingAlert.loadingText.setText(content);
      });
    }
  });
};

loading.hideLoading = function () {
  if (loading.loadingAlert) {
    loading.loadingAlert.close();
  }
};

module.exports = loading;
